Page({
  data: {
    goodsList: [
      {
        image: "demo/demo1.png",
        name: "商品A",
        price: "¥120"
      },
      {
        image: "demo/demo1.png",
        name: "商品B",
        price: "¥80"
      },
      {
        image: "demo/demo1.png",
        name: "商品C",
        price: "¥150"
      },
      {
        image: "demo/demo1.png",
        name: "商品A",
        price: "¥120"
      },
      {
        image: "demo/demo1.png",
        name: "商品B",
        price: "¥80"
      },
      {
        image: "demo/demo1.png",
        name: "商品C",
        price: "¥150"
      }
    ]
  },
  onLoad() {
    this.requestToBackend_goodsList();
  },
  
  // product_list
  requestToBackend_goodsList(){
    const that = this;
    // const apiUrl = 'https://localhost:3000/php/1.php'; // 替换成你的后端接口地址
    // const apiUrl = 'http://172.20.55.210:10086/product/getproducts'; // 替换成你的后端接口地址
    const apiUrl = 'http://172.20.55.210:10086/product'; // 替换成你的后端接口地址

    my.request({
      url: apiUrl,
      method: 'GET',
      // data: data，
      dataType: 'json',
      success: resp => {
        console.log(resp.data);
        goodsList = resp.data;
        my.alert({ content: 'success' });
      },
      fail: error => {
        console.error('请求失败：', error);
        my.alert({ content: '请求失败，详细错误信息请查看控制台' });
      },
    });
  }

});
